﻿
namespace SistemaLogistica.Windows.Panels
{
    using System;
    using System.Windows.Forms;
    using EDOSwit.Controls.Helpers;
    using SistemaLogistica.Business.Entities;
    using SistemaLogistica.Business.Logic;
    using SistemaLogistica.Windows.Helpers;

    public partial class FrmOptions : Form
    {
        public FrmOptions()
        {
            InitializeComponent();
        }

        private void FrmOptions_Load(object sender, EventArgs e)
        {
            if (!DesignMode)
            {
                this.txtDireccion.Text = Empresa.Direccion;
                this.txtEmail.Text = Empresa.Email;
                this.txtGerente.Text = Empresa.Gerente;
                this.txtRazonSocial.Text = Empresa.RazonSocial;
                this.txtRubro.Text = Empresa.Rubro;
                this.txtRUC.Text = Empresa.RUC;
                this.txtTelefono.Text = Empresa.Telefono;
                this.txtUbicacion.Text = Empresa.Ubicacion;
                this.txtIGV.Text = Empresa.IGV.ToString();
            }
        }

        private void Focus_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == Convert.ToChar(Keys.Enter))
            {
                e.Handled = true;
                SendKeys.Send("{TAB}");
            }
        }

        private void btnGuardar_Click(object sender, EventArgs e)
        {
            Empresa.Direccion = this.txtDireccion.Text;
            Empresa.Email = this.txtEmail.Text;
            Empresa.Gerente = this.txtGerente.Text;
            Empresa.RazonSocial = this.txtRazonSocial.Text;
            Empresa.Rubro = this.txtRubro.Text;
            Empresa.RUC = this.txtRUC.Text;
            Empresa.Telefono = this.txtTelefono.Text;
            Empresa.Ubicacion = this.txtUbicacion.Text;
            Empresa.IGV = Convert.ToDecimal(this.txtIGV.Text);
            this.DialogResult = DialogResult.OK;
        }

        private void btnBackup_Click(object sender, EventArgs e)
        {
            this.sfdBackUp.FileName = "BackUp_" + DateTime.Now.Day + "_" + DateTime.Now.Month + "_" + DateTime.Now.Year;
            if (this.sfdBackUp.ShowDialog() != DialogResult.Cancel)
            {
                Mensaje.ShowMessageAlert(this, Constantes.TituloMensaje, EmpresaManager.Instancia.GenerarCopiaDeSeguridad("Ferreteria", this.sfdBackUp.FileName));
            }
        }
    }
}
